package org.cbg.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import javax.swing.SwingConstants;

import org.cbg.frame.TraslationCommodityJFrame;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.panel.TraslationCommodityMainJPane;
import org.cbg.panel.TraslationWantBuyDahuabiModelJpanel;
import org.cbg.panel.TraslationWantBuyDaojuModelJpanel;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;

import com.tool.btn.MoBanBtn;

public class CBGDahuabiBuyBtn extends MoBanBtn {

    private int buyOrDa;
    private TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel;
    private TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel;


    public CBGDahuabiBuyBtn(String iconpath, int type, Color[] colors, Font font, int buyOrDa, String text,
            TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel) {
        super(iconpath, type, colors);
        // TODO Auto-generated constructor stub
        this.setText(text);
        this.buyOrDa = buyOrDa;
        this.traslationWantBuyDahuabiModelJpanel = traslationWantBuyDahuabiModelJpanel;
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
    }



    // public CBGDahuabiBuyBtn(String iconpath, int type, int buyOrDa, String
    // text,
    // TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel) {
    // super(iconpath, type);
    // // TODO Auto-generated constructor stub
    // this.setText(text);
    // this.buyOrDa = buyOrDa;
    // this.traslationWantBuyDaojuModelJpanel =
    // traslationWantBuyDaojuModelJpanel;
    // setFont(UIUtils.TEXT_FONT1);
    // setForeground(UIUtils.getColor("yellow"));
    // setVerticalTextPosition(SwingConstants.CENTER);
    // setHorizontalTextPosition(SwingConstants.CENTER);
    // }

    public CBGDahuabiBuyBtn(String iconpath, int type, Color[] colors, Font font, int buyOrDa, String text,
            TraslationWantBuyDaojuModelJpanel traslationWantBuyDaojuModelJpanel) {
        super(iconpath, type, colors);
        // TODO Auto-generated constructor stub
        this.setText(text);
        this.buyOrDa = buyOrDa;
        this.traslationWantBuyDaojuModelJpanel = traslationWantBuyDaojuModelJpanel;
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
    }



    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        TraslationCommodityMainJPane traslationCommodityMainJPane = TraslationCommodityJFrame
                .getTraslationCommodityJFrame().getTraslationCommodityMainJPane();
        // TODO Auto-generated method stub
        if (buyOrDa == 1) {
            /**
             * 获取收藏按钮
             */
            CBGDahuabiBuyBtn source = (CBGDahuabiBuyBtn) e.getSource();
            TrslationMainJframe.getTrslationMainJframe().setShoucangBtn(source.getParent().getComponent(2));

            // 清空面板内容
            traslationCommodityMainJPane.cleanNeirong();
            // 设置唯一标识
            traslationCommodityMainJPane.setName(traslationWantBuyDahuabiModelJpanel.getTupian().getName());
            // 商品编号
            traslationCommodityMainJPane.getNumber().setText(traslationWantBuyDahuabiModelJpanel.getTupian().getName());
            ;
            if (TrslationMainJframe.getTrslationMainJframe().getPanelOpen() == 8) {
                traslationCommodityMainJPane.getTupian().setIcon(
                        CutButtonImage.getCBG(traslationWantBuyDahuabiModelJpanel.getCollection().getSaletype(),
                                traslationWantBuyDahuabiModelJpanel.getCollection().getSaleskin(), 55, 53));
            } else {
                // 图片
                traslationCommodityMainJPane.getTupian().setIcon(
                        CutButtonImage.getCBG(traslationWantBuyDahuabiModelJpanel.getSalegoods().getSaletype(),
                                traslationWantBuyDahuabiModelJpanel.getSalegoods().getSaleskin(), 55, 53));
            }
            // 名称
            traslationCommodityMainJPane.getWupinming().setText(
                    traslationWantBuyDahuabiModelJpanel.getDahuabixia().getText());
            // 价格
            traslationCommodityMainJPane.getJine().setText(traslationWantBuyDahuabiModelJpanel.getPrice().getText());
            // 数据库对应表ID
            traslationCommodityMainJPane.getWupinming().setName(
                    traslationWantBuyDahuabiModelJpanel.getDahuabixia().getName());
            // 对应类型
            traslationCommodityMainJPane.getTupian().setName(traslationWantBuyDahuabiModelJpanel.getBuy().getName());

            if (traslationWantBuyDahuabiModelJpanel.getGongshiqiBiaoshi() == 0) {
                // 公示期剩余时间
                traslationCommodityMainJPane.getPublicitytime().setText(
                        traslationWantBuyDahuabiModelJpanel.getDahuabishang().getName());
                // 出售剩余时间
                traslationCommodityMainJPane.getSellingtime().setText("公示中");

                traslationCommodityMainJPane.setViewTrue(true);
                traslationCommodityMainJPane.getIncreaseAmount().setText(
                        "<html><body>同意支付<font color='#FF0000' >"
                                + new BigDecimal(traslationWantBuyDahuabiModelJpanel.getPrice().getText()).multiply(
                                        new BigDecimal(0.2)).setScale(0, BigDecimal.ROUND_HALF_UP)
                                + "</font>元预定费</body></html>");
                // 价格
                traslationCommodityMainJPane.getJine().setText(
                        traslationWantBuyDahuabiModelJpanel.getPrice().getText()
                                + "+"
                                + new BigDecimal(traslationWantBuyDahuabiModelJpanel.getPrice().getText()).multiply(
                                        new BigDecimal(0.2)).setScale(0, BigDecimal.ROUND_HALF_UP));
            } else {
                // 公示期剩余时间
                traslationCommodityMainJPane.getPublicitytime().setText("已过公示期");
                // 出售剩余时间
                traslationCommodityMainJPane.getSellingtime().setText(
                        traslationWantBuyDahuabiModelJpanel.getDahuabishang().getName());
                traslationCommodityMainJPane.setViewTrue(false);
            }
            // 卖家ID
            traslationCommodityMainJPane.getSellerID()
                    .setText(traslationWantBuyDahuabiModelJpanel.getPrice().getName());
            if (traslationWantBuyDahuabiModelJpanel.getDanjia().getName() != null) {
                // 买家ID
                traslationCommodityMainJPane.getAssignID().setText(
                        traslationWantBuyDahuabiModelJpanel.getDanjia().getName());
            }
            if (traslationWantBuyDahuabiModelJpanel.getTupian().getName()
                    .equals(traslationCommodityMainJPane.getName())) {
                // 收藏
                traslationCommodityMainJPane.getShoucang().setIcons(
                        traslationWantBuyDahuabiModelJpanel.getShoucang().getIcons());
            }

            /**
             * 传输数据给服务器获取商品信息 1、上传商品ID 2、发送给服务器
             */
            String sendmes = Agreement.getAgreement().searchBuyAgreement(
                    traslationWantBuyDahuabiModelJpanel.getTupian().getName());
            SendMessageUntil.toServer(sendmes);

            // 展示购买页面
            // FormsManagement.showForm(79);

        } else {
            /**
             * 获取收藏按钮
             */
            CBGDahuabiBuyBtn source = (CBGDahuabiBuyBtn) e.getSource();
            TrslationMainJframe.getTrslationMainJframe().setShoucangBtn(source.getParent().getComponent(2));

            // 清空面板内容
            traslationCommodityMainJPane.cleanNeirong();
            // 设置唯一标识
            traslationCommodityMainJPane.setName(traslationWantBuyDaojuModelJpanel.getTupian().getName());
            // 商品编号
            traslationCommodityMainJPane.getNumber().setText(traslationWantBuyDaojuModelJpanel.getTupian().getName());
            if (traslationWantBuyDaojuModelJpanel.getSalegoods() == null) {
                traslationCommodityMainJPane.getTupian().setIcon(
                        CutButtonImage.getCBG(traslationWantBuyDaojuModelJpanel.getCollection().getSaletype(),
                                traslationWantBuyDaojuModelJpanel.getCollection().getSaleskin(), 55, 53));
            } else {
                // 图片
                traslationCommodityMainJPane.getTupian().setIcon(
                        CutButtonImage.getCBG(traslationWantBuyDaojuModelJpanel.getSalegoods().getSaletype(),
                                traslationWantBuyDaojuModelJpanel.getSalegoods().getSaleskin(), 55, 53));
            }
            // 名称
            traslationCommodityMainJPane.getWupinming().setText(
                    traslationWantBuyDaojuModelJpanel.getDahuabixia().getText());
            // 价格
            traslationCommodityMainJPane.getJine().setText(traslationWantBuyDaojuModelJpanel.getPrice().getText());

            // 数据库对应表ID
            traslationCommodityMainJPane.getWupinming().setName(
                    traslationWantBuyDaojuModelJpanel.getDahuabixia().getName());
            // 对应类型
            traslationCommodityMainJPane.getTupian().setName(traslationWantBuyDaojuModelJpanel.getBuy().getName());

            // 出售剩余时间
            if (traslationWantBuyDaojuModelJpanel.getGongshiqiBiaoshi() == 0) {
                // 公示期剩余时间
                traslationCommodityMainJPane.getPublicitytime().setText(
                        traslationWantBuyDaojuModelJpanel.getDanjia().getText());
                // 出售剩余时间
                traslationCommodityMainJPane.getSellingtime().setText("公示中");

                traslationCommodityMainJPane.setViewTrue(true);
                traslationCommodityMainJPane.getIncreaseAmount().setText(
                        "<html><body>同意支付<font color='#FF0000' >"
                                + new BigDecimal(traslationWantBuyDaojuModelJpanel.getPrice().getText()).multiply(
                                        new BigDecimal(0.2)).setScale(0, BigDecimal.ROUND_HALF_UP)
                                + "</font>元宝预定费</body></html>");

                // 价格
                traslationCommodityMainJPane.getJine().setText(
                        traslationWantBuyDaojuModelJpanel.getPrice().getText()
                                + "+"
                                + new BigDecimal(traslationWantBuyDaojuModelJpanel.getPrice().getText()).multiply(
                                        new BigDecimal(0.2)).setScale(0, BigDecimal.ROUND_HALF_UP));
            } else {
                // 公示期剩余时间
                traslationCommodityMainJPane.getPublicitytime().setText("已过公示期");
                // 出售剩余时间
                traslationCommodityMainJPane.getSellingtime().setText(
                        traslationWantBuyDaojuModelJpanel.getDanjia().getText());
                traslationCommodityMainJPane.setViewTrue(false);
            }
            // 卖家ID
            traslationCommodityMainJPane.getSellerID().setText(traslationWantBuyDaojuModelJpanel.getPrice().getName());
            // 买家ID
            if (traslationWantBuyDaojuModelJpanel.getDanjia().getName() != null) {
                traslationCommodityMainJPane.getAssignID().setText(
                        traslationWantBuyDaojuModelJpanel.getDanjia().getName());
            }
            if (traslationWantBuyDaojuModelJpanel.getTupian().getName().equals(traslationCommodityMainJPane.getName())) {
                // 收藏
                traslationCommodityMainJPane.getShoucang().setIcons(
                        traslationWantBuyDaojuModelJpanel.getShoucang().getIcons());
            }

            /**
             * 传输数据给服务器获取商品信息 1、上传商品ID 2、发送给服务器
             */
            String sendmes = Agreement.getAgreement().searchBuyAgreement(
                    traslationWantBuyDaojuModelJpanel.getTupian().getName());
            SendMessageUntil.toServer(sendmes);

            // FormsManagement.showForm(79);

        }

    }

}
